package com.siwei.mes.entity.experiment.fineAggregate;

import com.alibaba.fastjson.JSONObject;
import com.siwei.mes.common.util.JsonUtils;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.experimental.Accessors;
import org.apache.commons.lang.StringUtils;

import java.util.Collections;
import java.util.List;
import java.util.Map;

/**
 * @Description: 细骨料-氯离子含量
 * @Version: 1.0
 * @author: YANGKE
 * @date: 2024/02/25 21:29
 */
@Data
@Accessors(chain = true)
public class FineAggregateLlzhl {
    @ApiModelProperty(value = "换算系数")
    private String hsxs = "";
    @ApiModelProperty(value = "体积比")
    private String tjb = "";
    @ApiModelProperty(value = "平均值")//1
    private String pjz = "";
    @ApiModelProperty(value = "单项结论")//1
    private String dxjl = "";
    @ApiModelProperty(value = "检测日期")
    private String jcrq = "";
    @ApiModelProperty(value = "氯离子含量信息")
    private List<FineAggregateLlzhl.LlzhlInfo> llzhlInfo = Collections.singletonList(new FineAggregateLlzhl.LlzhlInfo());

    @Data
    @Accessors(chain = true)
    @ApiModel("氯离子含量信息")
    public class LlzhlInfo {
        @ApiModelProperty(value = "硝酸银浓度")
        private String xsynd = "";
        @ApiModelProperty(value = "样品体积")
        private String yptj = "";
        @ApiModelProperty(value = "空白体积")
        private String kbtj = "";
        @ApiModelProperty(value = "样品重量")
        private String ypzl = "";
        @ApiModelProperty(value = "氯离子含量")
        private String llzhl = "";
    }

    /**
     * 字符串转成对象 然后再转成json
     *
     * @param object
     * @return
     */
    private static JSONObject toJsonObject(Object object) {
        FineAggregateLlzhl entity = new FineAggregateLlzhl();
        if (object == null) {
            return JsonUtils.beanToObject(entity);
        }
        if (object instanceof String) {
            entity = JsonUtils.getObject((String) object, FineAggregateLlzhl.class);
        } else if (object instanceof JSONObject) {
            entity = JsonUtils.getObject((JSONObject) object, FineAggregateLlzhl.class);
        }
        return JsonUtils.beanToObject(entity);
    }

    public static String checkIsMust(JSONObject objJson, String name) {
        if (objJson.isEmpty()) {
            return null;
        }
        FineAggregateLlzhl entity = JsonUtils.getObject(objJson, FineAggregateLlzhl.class);
        if (entity == null) {
            return "存在必检项(" + name + ")未检测，请先检测！";
        }
        if (StringUtils.isBlank(entity.getPjz()) || "null".equals(entity.getPjz())) {
            return "存在必检项(" + name + ")未检测，请先检测！";
        }
        /*if (StringUtils.isBlank(entity.getDxjl()) || "null".equals(entity.getDxjl())) {
            return "存在必检项(" + name + ")未检测，请先检测！";
        }*/
        return null;
    }

    public static void setValue(FineAggregateLlzhl entity, Map<String, Object> data) {
        List<FineAggregateLlzhl.LlzhlInfo> llzhlInfoList = entity.getLlzhlInfo();
        FineAggregateLlzhl.LlzhlInfo llzhlInfo = llzhlInfoList.get(1);
        if (data.get("m1") != null) {
            llzhlInfo.setYptj(data.get("m1").toString());
        }
        if (data.get("m2") != null) {
            llzhlInfo.setKbtj(data.get("m2").toString());
        }
        if (data.get("m3") != null) {
            llzhlInfo.setYpzl(data.get("m3").toString());
        }
        if (data.get("m4") != null) {
            llzhlInfo.setLlzhl(data.get("m4").toString());
        }
        if (data.get("m0") != null) {
            llzhlInfo.setXsynd(data.get("m0").toString());
        }
    }
}
